﻿Public Class frmDoanhThu

    Private Sub frmDoanhThu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cbxThang.Items.Add("Tất cả")
        Dim i As Integer = 1
        Dim j As Integer = 2010
        While i <= 12
            cbxThang.Items.Add(i)
            i = i + 1
        End While
        While j <= 2030
            cbxNam.Items.Add(j)
            j = j + 1
        End While
        cbxThang.SelectedIndex = 0
        cbxNam.SelectedIndex = 0
    End Sub

    Private Sub btnThongKe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThongKe.Click
        Dim th As TapHoa = New TapHoa()
        If cbxThang.SelectedIndex = 0 Then
            th.m_strThang = 20
        Else
            th.m_strThang = Integer.Parse(cbxThang.SelectedItem)
        End If
        th.m_strNam = Integer.Parse(cbxNam.SelectedItem)
        If txtTenSanPham.Text.Length = 0 Then
            th.m_strTenHangHoa = 1
        Else
            th.m_strTenHangHoa = txtTenSanPham.Text
        End If
        dgvDanhSach.DataSource = TapHoaDAO.ThongKeDoanhThu(th)
        If dgvDanhSach.Rows.Count = 1 Then
            MessageBox.Show("Không có doanh thu trong thời gian này !")
            cbxThang.Focus()
        Else
            Dim row As Integer = 0
            Dim TongTien As Integer = 0
            Dim SoLuong As Integer = 0
            While row < dgvDanhSach.Rows.Count - 1
                TongTien = TongTien + Integer.Parse(dgvDanhSach.Rows(row).Cells(2).Value.ToString())
                SoLuong = SoLuong + Integer.Parse(dgvDanhSach.Rows(row).Cells(1).Value.ToString())
                row = row + 1
            End While
            lbDoanhThu.Text = TongTien.ToString()
            lbSoLuong.Text = SoLuong.ToString()
            lbThoiGian.Text = cbxThang.SelectedItem.ToString() + "/" + cbxNam.SelectedItem.ToString()
        End If
    End Sub
End Class